Public Class FormChangePassword

    Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
        CmdPro.Begin()
        Try

            CmdPro.Parameters("@UserName") = App.UserName
            CmdPro.Parameters("@Password") = Crypto.PasswordHash(App.UserName, Me.txtPassword.Text)
            Dim dt = CmdPro.ExecuteDataTable("ChangePassword")
            If dt.Rows.Count <> 1 Then
                MsgBox("Invalid old password!")
                Exit Sub
            End If
            If txtNewPassword.Text = "" Then
                MsgBox("New password can not be empty")
                txtNewPassword.Focus()
                Exit Sub
            End If
            If Me.txtNewPassswordConfirm.Text <> Me.txtNewPassword.Text Then
                MsgBox("New password is not correct!")
                Exit Sub
            End If

            CmdPro.Parameters("@UserName") = App.UserName
            CmdPro.Parameters("@Password") = Crypto.PasswordHash(App.UserName, Me.txtNewPassword.Text)
            CmdPro.ExecuteNonQueryNoParameter("ChangePasswordConfirm")
            Me.DialogResult = Windows.Forms.DialogResult.OK

            CmdPro.Commit()
        Catch ex As Exception
            CmdPro.Rollback()
            MsgBox(ex.Message)
        End Try
    End Sub


    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Dbinterface.OpenConnection()
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub FormChangePassword_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class